package com.tcgroup.phone.base_core.widget;

import android.content.Context;
import android.util.AttributeSet;

import androidx.databinding.ObservableField;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.tcgroup.phone.base_core.utils.KLog;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/25.
 * 包名: com.tcgroup.phone.base_core.widget
 * 类名: OSAndroidMvvm
 */
public class SSmartRefreshLayout extends SmartRefreshLayout {

    public String TAG = "SSmartRefreshLayout";

    public boolean smartFinishRefresh = false;
    public boolean smartFinishLoadMore = false;

    public SSmartRefreshLayout(Context context) {
        super(context);
    }

    public SSmartRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SSmartRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setSmartEnableRefresh(ObservableField<Boolean> enabled){
        setEnableRefresh(enabled.get());
    }

    public void setSmartEnableLoadMore(ObservableField<Boolean> enabled){
        setEnableLoadMore(enabled.get());
    }

    public boolean getSmartFinishRefresh() {
        KLog.i(TAG,"getSmartFinishRefresh>>"+this.smartFinishRefresh);
        return this.smartFinishRefresh;
    }

    public boolean getSmartFinishLoadMore() {
        KLog.i(TAG,"getsmartFinishLoadMore>>"+this.smartFinishLoadMore);
        return this.smartFinishLoadMore;
    }

    public void setSmartFinishRefresh(boolean flag){
        if (this.smartFinishRefresh == flag){
            KLog.i(TAG,"setSmartFinishRefresh>>重复设置");
            return;
        }else {
            KLog.i(TAG,"setSmartFinishRefresh>>"+flag);
            this.smartFinishRefresh = flag;
            finishRefresh(flag);
        }
    }

    public void setSmartFinishLoadMore(boolean flag){
        if (this.smartFinishLoadMore == flag){
            KLog.i(TAG,"setSmartFinishLoadMore>>重复设置");
            return;
        }else {
            KLog.i(TAG,"smartFinishLoadMore>>"+flag);
            this.smartFinishLoadMore = flag;
            finishLoadMore(flag);
        }
    }

}
